package crp.core.workflow.app.loaders;

import com.qwlabs.lang.C2;
import com.qwlabs.security.Caller;
import crp.core.workflow.domain.models.WorkflowCandidate;
import crp.core.workflow.domain.models.WorkflowCandidateType;
import crp.core.workflow.domain.services.WorkflowCandidateLoader;

import javax.enterprise.context.ApplicationScoped;
import javax.validation.constraints.NotNull;
import java.util.Set;

@ApplicationScoped
public class WorkflowCandidatePermissionLoader implements WorkflowCandidateLoader {
    @Override
    public Set<WorkflowCandidate> load(@NotNull Caller caller) {
        return C2.set(caller.permissions().raw(), permission -> WorkflowCandidate.builder()
                .type(WorkflowCandidateType.PERMISSION)
                .target(permission)
                .build());
    }
}
